#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <mypushbutton.h>
#include <QDebug>
#include <QTimer>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //配置主场景
    //设置固定大小
    setFixedSize(320,588);
    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    //设置标题
    setWindowTitle("翻金币！！欢迎游戏");
    //退出按钮的实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    //开始按钮
    MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,height()*0.7);

    //实例化选择关卡场景
    chooseScene = new ChooseLevelScene;

    //监听选择关卡的返回按钮的信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        chooseScene->hide();//将关卡选择场景隐藏
        this->show();//重新显示主场景
    });


    connect(startBtn,&MyPushButton::clicked,[=]{
        qDebug()<<"点击了开始";
        //做一个弹起的特效
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入到选择关卡场景
        QTimer::singleShot(300,this,[=](){
            //将自身隐藏
            this->hide();
            //显示选择关卡的场景
            chooseScene->show();


        });


    });


}
void MainWindow::paintEvent(QPaintEvent *)
{
    //画初始界面的背景图
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

}

MainWindow::~MainWindow()
{
    delete ui;
}
